import 'package:aichat_flutter_wallet/module/module_dapp/widgets/hover_status.dart';
import 'package:aichat_flutter_wallet/module_common/utils/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

enum ButtonType { private, defaultType, white, delete,deleteComplete }

class PublicButton extends StatefulWidget {
  String text;
  Function onClick = () {};
  EdgeInsetsGeometry? margin;
  ButtonType type = ButtonType.defaultType;
  double radius = 10.w;
  double height = 46.w;
  bool disabledStatus = false;
  bool hasHov = true;
  Widget? image;

  PublicButton(
      {required this.text,
      void Function()? onClick,
      this.margin = const EdgeInsets.only(left: 20, right: 20),
      this.type = ButtonType.defaultType,
      this.radius = 10,
      this.height = 46,
      this.disabledStatus = false,
      this.hasHov = true,
      this.image})
      : onClick = onClick ?? (() {});

  @override
  _PublicButtonState createState() => _PublicButtonState();
}

class _PublicButtonState extends State<PublicButton> {



  get defaultColor {
    if (widget.type == ButtonType.defaultType) {
      return Color.fromRGBO(246, 243, 255, 1);
    }
    if (widget.type == ButtonType.private) {
      return (widget.disabledStatus && widget.hasHov)
          ? Color.fromRGBO(183, 165, 255, 1)
          : Color.fromRGBO(134, 103, 254, 1);
    }
    if (widget.type == ButtonType.white) {
      return Color.fromRGBO(255, 255, 255, 1);
    }
    if (widget.type == ButtonType.delete) {
      return Color.fromRGBO(244, 101, 77, 0.02);
    }
    if (widget.type == ButtonType.deleteComplete) {
      return Color.fromRGBO(244, 101, 77, 0.02);
    }
  }

  get hoverColor {
    if (widget.type == ButtonType.defaultType) {
      return Color.fromRGBO(134, 103, 254, .3);
    }
    if (widget.type == ButtonType.private) {
      return Color.fromRGBO(134, 103, 254, .3);
    }
    if (widget.type == ButtonType.white) {
      return Color.fromRGBO(255, 255, 255, 1);
    }
    if (widget.type == ButtonType.delete) {
      return Color.fromRGBO(244, 101, 77, 0.02);
    }
    if (widget.type == ButtonType.deleteComplete) {
      return Color.fromRGBO(244, 101, 77, 0.02);
    }

  }

  get fontColor {
    if (widget.type == ButtonType.defaultType) {
      return widget.disabledStatus ? Color.fromRGBO(29, 0, 97, .3) : Color.fromRGBO(29, 0, 97, 1);
    }
    if (widget.type == ButtonType.private) {
      return widget.disabledStatus ? Color.fromRGBO(255, 255, 255, .3) : Color.fromRGBO(255, 255, 255, 1);
    }
    if (widget.type == ButtonType.white) {
      return widget.disabledStatus ? Color.fromRGBO(51, 51, 51, 1) : Color.fromRGBO(51, 51, 51, 1);
    }
    if (widget.type == ButtonType.delete) {
      return widget.disabledStatus ? Color.fromRGBO(244, 101, 77, 1) : Color.fromRGBO(244, 101, 77, 1);
    }
    if (widget.type == ButtonType.deleteComplete) {
      return Color.fromRGBO(134, 103, 254, 1);
    }
  }

  get borderColor {
    if(widget.type == ButtonType.delete){
      return  AppColors.c_F4654D;
    }
    if(widget.type == ButtonType.deleteComplete){
      return Color.fromRGBO(134, 103, 254, 1);
    }
    return  Colors.transparent;
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      height: widget.height,
      margin: widget.margin,
      child: HoverStatus(
        radius: widget.radius,
        onPressed: () {
          widget.onClick();
        },
        borderColor: borderColor,
        defaultColor: defaultColor,
        hoverColor: widget.hasHov ? hoverColor : defaultColor,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Visibility(
                visible: widget.image != null,
                child: Row(
                  children: [
                    widget.image ?? Container(),
                    SizedBox(
                      width: 10.w,
                    )
                  ],
                )),
            Align(
              child: Text(
                widget.text,
                style: TextStyle(fontSize: 12.sp, color: fontColor, fontWeight: FontWeight.w500, height: 17.w / 12.w),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
